<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>随附单录入界面</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "随附单数据",
        module: 'save',
        numCount: '1',
        columns: [{
            index: "ID",
            name: "id",
            hidden: true
        }, {
            index: "BID",
            name: "temp_id",
            hidden: true
        }, {
            index: "declaration",
            name: "declaration.id",
            hidden: true
        }, {
            index: "suifudan_co_cn",
            name: "suifudan_co_cn",
            hidden: true
        }, {
            index: "suifudan_co",
            name: "suifudan_co",
            label: "随附单名称",
            type: 'dropdown',
            data: [["1 进口许可证", "1"],
                ["2 两用物项和技术进口许可证", "2"],
                ["3 两用物项和技术出口许可证", "3"],
                ["4 出口许可证", "4"],
                ["5 纺织品临时出口许可证", "5"],
                ["6 旧机电产品禁止进口", "6"],
                ["7 自动进口许可证", "7"],
                ["8 禁止出口商品", "8"],
                ["9 禁止进口商品", "9"],
                ["A 入境货物通关单", "A"],
                ["B 出境货物通关单", "B"],
                ["C 出/入境货物通关单（毛坯钻石用）", "D"],
                ["E 濒危物种允许出口证明书", "E"],
                ["F 濒危物种允许进口证明书", "F"],
                ["G 两用物项和技术出口许可证(定向)", "G"],
                ["H 港澳OPA纺织品证明", "H"],
                ["I 精神药物进(出)口准许证", "I"],
                ["J 黄金及其制品进出口准许证或批件", "J"],
                ["K 深加工结转申请表", "K"],
                ["L 药品进出口准许证", "L"],
                ["M 密码产品和设备进口许可证", "M"],
                ["O 自动进口许可证(新旧机电产品)", "O"],
                ["P 固体废物进口许可证", "P"],
                ["Q 进口药品通关单", "Q"],
                ["R 进口兽药通关单", "R"],
                ["S 进出口农药登记证明", "S"],
                ["T 银行调运现钞进出境许可证", "T"],
                ["U 合法捕捞产品通关证明", "U"],
                ["W 麻醉药品进出口准许证", "W"],
                ["X 有毒化学品环境管理放行通知单", "X"],
                ["Y 原产地证明", "Y"],
                ["Z 音像制品进口批准单或节目提取单", "Z"],
                ["c 内销征税联系单", "c"],
                ["e 关税配额外优惠税率进口棉花配额", "e"],
                ["q 国别关税配额证明", "q"],
                ["r 预归类标志", "r"],
                ["s 适用ITA税率的商品用途认定证明", "s"],
                ["t 关税配额证明", "t"],
                ["v 自动进口许可证(加工贸易)", "v"],
                ["x 出口许可证(加工贸易)", "x"],
                ["y 出口许可证(边境小额贸易)", "y"]],
            minLength: 1,
            itemSelected: function (event, ui) {
                var co_cn = ui.item[0].replace(/(\d|\w) /, "");
                $("input[name='suifudan_co_cn']").val(co_cn);
                $(event.target).val(co_cn);
            }
        }, {
            index: "suifudan_no",
            name: "suifudan_no",
            label: "随附单编号"
        }],
        form: {
            'url': 'saveOrUpdate',
            'data': function () {
                var id = "${id}";
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "find?id=" + id,
                               async: false,
                               cache: false,
                               success: function (data) {
                                   dataValue = data;
                               }
                           });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                jw.confirm("请选择是否继续录入？", function () {
                    history.go(0)
                }, function () {
                    history.go(-1)
                })
            }
        },
        buttons: {
            custom: []
        }
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
        $("input[name='temp_id']").val(
                "${tid}" == "" ? $("input[name='temp_id']").val() : "${tid}");
        $("input[name='declaration.id']").val(
                "${did}" == "" ? $("input[name='declaration.id']").val() : "${did}");

//        $.ajax({
//                   url: "../business/hgdata-initData",
//                   success: function (data) {
//                       var sfdCode = data.data.HGD_7;
//
//                       initDropDown("#form_in_control_4", "#form_in_control_5", sfdCode, 1);
//                   }
//               });
        $("input[name='suifudan_co_cn']").focus();
        var co_cn_lab = $("input[name='control_suifudan_co_dropdown']");
        var _val = co_cn_lab.val();
        co_cn_lab.val(_val.replace(/(\d|\w) /, ""));
    });

    function getIndex(objArray) {
        var index = "";
        objArray.each(function (i, n) {
            if ($(event.srcElement).attr("id") == $(n).attr("id")) {
                index = i;
                return false;
            }
        });
        return index;
    }
    ;

    /**
     *初始化报关下拉框
     *@param showid 显示用的输入框
     *@param setValueId 保存正式值的输入框
     *@param data 数据源
     */
    function initDropDown(showid, setValueId, data, minlen) {
        var obj = $(showid);
        var objValueInput = $(setValueId);
        var datasource = new Array();
        if (minlen == 0) {

        } else if (minlen == "" || minlen == undefined || minlen == null) {
            minlen = 2;
        }
        $.each(data, function (i, n) {
            datasource.push(n.code + " " + n.name);
        });
        obj.autocomplete({
                             minLength: minlen, source: datasource,
                             autoFocus: true, delay: 0, select: function (event, ui) {
                var s = ui.item.label;
                var s_num = s.substring(0, 3);
                if (s_num == "242" || s_num == "217" || s_num == "113" || s_num == "246" || s_num
                                                                                            == "139") {
                    alert("特别提示：出口该国家须做装运前检验！");
                }

                objValueInput.val(s.substring(0, s.indexOf(" ")));
                obj.val(s.substring(s.indexOf(" ") + 1, s.length));
                var objArray = $("#outer input[id][type!=hidden][disabled!=disabled]");
                var inputIndex = getIndex(objArray);
                var nextInput = objArray.eq(++inputIndex);
                nextInput.select();
                return false;
            }
                         });
        if (minlen == 0) {
            //	obj.bind("focus",function(event){obj.autocomplete("search");});
            //	obj.bind("click",function(event){obj.autocomplete("search");});
            dropdownClickEvent(showid);
        }
    }

    //miniLength为0时，下拉框输入框被点击或者获得焦点会打开下拉框
    function dropdownClickEvent(id) {
        var obj = $(id);
        obj.bind("focus", function (event) {
            obj.autocomplete("search");
        });
        obj.bind("click", function (event) {
            obj.autocomplete("search");
        });
    }
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
</body>
</html>
